package cn.com.taurus.mail.controller;

import cn.com.taurus.biz.AdminsBiz;
import cn.com.taurus.entity.Admins;
import cn.com.taurus.mail.DemoTest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Controller
public class EmailController {
    String code = "";
    /**
     * 开启线程池发送验证码
     * @param email 发送的邮箱
     * @return
     */
    @RequestMapping(value = "/Anonymous/getEmailCode")
    @ResponseBody
    public String getEmailCode(String email){
        ExecutorService pool = Executors.newFixedThreadPool(3);
        pool.execute(new Runnable(){
            public void run(){
                DemoTest test = new DemoTest();
                code ="{\"code\":"+test.getCode(email)+"}";
                System.err.println("线程中："+code);
                //发送验证码并返回验证码
            }
        });

        //线程关闭
        pool.shutdown();
        while(true) {
            //判断线程是否关闭
            if (pool.isTerminated()) {
                System.err.println("线程外："+code);
                System.out.println("线程结束");
                break;
            }
        }

        return code;
    }



//    @RequestMapping(value = "/Anonymous/getEmailCode")
//    @ResponseBody
//    public String getEmailCode(String email){
//        String code = "";
//        DemoTest test = new DemoTest();
//        code ="{\"code\":"+test.getCode(email)+"}";
//        //发送验证码并返回验证码
//        return code;
//    }
}
